#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
#define ll long long
char s[N];
ll sum[N];
int len;
int k;
struct node {
    int id;
    int dis;
} pos[N];
bool check(int x) {
    for (int i = 1; i <= len; i++) {
        int j = i + x - 1;
        j = min(j, len);
        if (sum[j] - sum[i - 1] + k >= x) {
            // cout<<sum[j]<<" "<<sum[i-1]<<endl;
            // cout<<i<<" "<<j<<endl;
            return 1;
        }
    }
    return 0;
}
int main() {
    cin >> s + 1 >> k;
    len = strlen(s + 1);
    ll num = 0;
    for (int i = 1; i <= len; i++) {
        if (s[i] == 'X') {
            sum[i] = ++num;
        }
        else {
            sum[i] = sum[i - 1];
        }
    }

    if (len - sum[len] <= k) {
        printf("%d\n", len);
        return 0;
    }
    /*for(int i=1;i<=len;i++) {
        sum[i]+=sum[i-1];
    }*/
    // check(6);
    int l = 0, r = len;
    while (l < r) {
        int mid = (l + r + 1) >> 1;
        if (check(mid)) {
            l = mid;
        }
        else {
            r = mid - 1;
        }
    }
    cout << l << endl;
}